home *** CD-ROM | disk | FTP | other *** search
- :: -------------------------------------------------------------------
- ::
- :: download.bat -- Maintain a small local gnuwin32 package archive
- :: whithin the cmd console of windows XP
- ::
- :: author : Mathias Michaelis <michaelis@tcnet.ch>
- :: date : May 4, 2006
- :: version: 0.6.13
- ::
- :: Copyright (c) 2006 by Mathias Michaelis, <michaelis@tcnet.ch>
- ::
- :: -------------------------------------------------------------------
- ::
- :: Permission is granted to copy, distribute and/or modify this document
- :: under the terms of the GNU Free Documentation License, Version 1.2
- :: or any later version published by the Free Software Foundation;
- :: with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
- :: Texts. A copy of the license is included in the file LICENSE.TXT
- ::
- ::
- :: Acknowledgments
- :: ---------------
- ::
- :: See file README.TXT in this directory. Thanks to all who advised me,
- :: gave me some hints, sent me some patches or encouraged me to go on!
- ::
- @echo off
- setlocal ENABLEEXTENSIONS
- set LC_ALL=C
-
- ::
- :: Customization
- :: -------------
- ::
- :: Select one or more of the following mirrors first! Please separate
- :: the mirrors by space, e.g. GNUWIN32_MIRROR="umn unc".
- ::
- :: aleron (US)
- :: belnet (BE)
- :: easynews (US)
- :: heanet (IE)
- :: internap (US)
- :: jaist (JP)
- :: keihanna (JP)
- :: kent (UK)
- :: mesh (DE)
- :: optusnet (AU)
- :: ovh (FR)
- :: puzzle (CH)
- :: switch (CH)
- :: umn (US)
- :: unc (US)
- :: voxel (US)
- ::
- if .%GNUWIN32_MIRROR%==. set GNUWIN32_MIRROR=umn
-
- ::
- ::
- :: Process command line options. This can be a list of some above
- :: mentioned mirrors ans/or the verbose option switch -v.
- ::
- set GNUWIN32_CMDLINE_MIRROR=
-
- :command_line
- if .%1==. goto command_line_end
- if "%1"=="-v" goto set_verbose
- set GNUWIN32_CMDLINE_MIRROR=%GNUWIN32_CMDLINE_MIRROR% %1
- shift
- goto command_line
-
- :set_verbose
- set GNUWIN32_VERBOSE=TRUE
- shift
- goto command_line
-
- ::
- :: If command line options were specified, overwrite environment
- :: variables
- ::
- :command_line_end
- if "%GNUWIN32_CMDLINE_MIRROR%"=="" goto environment
- set GNUWIN32_MIRROR=%GNUWIN32_CMDLINE_MIRROR:~1%
- set GNUWIN32_LOAD=
- set GNUWIN32_CMDLINE_MIRROR=
-
- ::
- :: After the mirrors are known, the download address of that mirrors
- :: can be constructed (if not already done):
- ::
- :environment
- if not .%GNUWIN32_LOAD%==. goto set_wgetrc
- set GNUWIN32_LOAD=http://%GNUWIN32_MIRROR:"=%.dl.sourceforge.net/sourceforge/gnuwin32/
- set GNUWIN32_LOAD=%GNUWIN32_LOAD: =.dl.sourceforge.net/sourceforge/gnuwin32/ http://%
-
- ::
- :: Perhaps the user has specified her/his own .wgetrc file by means
- :: of the WGETRC environment variable. If not, then use the one in
- :: the local bin directory
- ::
- :set_wgetrc
- if ".%WGETRC%"=="." set WGETRC=%CD%\bin\wget.ini
-
- ::
- :: If we are in verbose mode, tell what we're going to do
- ::
- if "%GNUWIN32_VERBOSE%"=="" goto clean_old_lists
-
- echo =
- echo = URL of file list:
- echo = https://sourceforge.net/project/showfiles.php?group_id=23617
- echo =
- echo = List of mirrors (high priority first):
- echo = %GNUWIN32_MIRROR%
- echo =
- echo = List of URLs (high priority first):
- echo %GNUWIN32_LOAD% >loadlist.txt
- bin\sed "s/ *$//;s/.*/= &/;s/[^ =] /\n= /g" loadlist.txt
- echo =
- del loadlist.txt
-
- ::
- :: Clean up old filelists etc.
- ::
- :clean_old_lists
- if exist filelist.txt del filelist.txt
- if exist packages.txt del packages.txt
-
- ::
- :: First, get the filelist form the official project site on sourceforge.net
- ::
- if not "%GNUWIN32_VERBOSE%"=="" echo = Downloading file list from sourceforge.net ...
- bin\wget --ca-certificate=bin\cacert.pem -O project.html https://sourceforge.net/project/showfiles.php?group_id=23617
- if exist project.html goto normalize
- echo Couldn't download gnuwin32 project site from sourceforge.net
- goto bye
-
- ::
- :: Normalize filetable.html: Every tag has to be in its own line. Empty lines
- :: aren't allowed
- ::
- :normalize
- if not "%GNUWIN32_VERBOSE%"=="" echo = Analysing file list ...
- bin\sed -n "s/>/>\n/g;s/</\n</g;s/\(\s*\n\)\+\s*/\n/g;s/^\n\+//;s/\n\+$//;s/^\s\+//;s/.\+/&/p" project.html >normal.html
- del project.html
-
- ::
- :: Convert the normalized HTML file in plain text. Take only the
- :: information that is relevant here: The package list. Because
- :: This procedure depends very much on the way the HTML file is
- :: programmed. That's why it's a bit risky. If this script is not
- :: up-to-date, this step may fail!
- ::
- bin\sed -n "/^<tr\s\+class\s*=\s*""""package""""\s*>/{n;n;n;s/.*/ &/p};/^<a href=""""http:\/\/prdownloads.sourceforge.net\/gnuwin32\/\(.*-\(bin\|doc\|lib\|dep\)\.zip\)?download"""">$/Is//\1/p" normal.html >filelist.tmp
- bin\sed "/^ /d" filelist.tmp >filelist.txt
- del normal.html
-
- ::
- :: Assume: filelist.txt is already sorted by filenames and fileversion
- :: so that new versions are listed first.
- ::
- :: Now create a package list from the files with the newest versions
- ::
- :: bin\sed -n "/^[^ ]/s/\(.*\)-...\.zip/\1/p" filelist.txt >packages.tmp
- :: bin\sed ":x;N;s/^\(\([^-]*-[^[:digit:]]\)*[^-]*\)\(-[[:digit:]].*\)\?\n\1\(-[[:digit:]].*\)\?$/\1\3/;tx;P;D" packages.tmp >packages.txt
- ::
- :: New: filelist.tmp contains also package information. This simplifies
- :: the process of generating a package list.
- ::
- bin\sed -n "/^ /{n;s/\(.*\)-...\.zip/\1/p}" filelist.tmp >packages.txt
-
- ::
- :: Cancel all packages which name are listed within the include.txt and
- :: the exclude.txt files.
- ::
- if exist include.txt bin\sed -n "s/\s*#.*$//;tx;:x;s/^\s*$//;t;s/\s*//g;p" include.txt >include.tmp
- if exist include.tmp bin\sed "s/^\(\([^-]*-[^[:digit:]]\)*[^-]*\).*$/\1 -/" include.tmp >exclude.tmp
- if exist exclude.txt bin\sed -n "s/\s*#.*$//;tx;:x;s/^\s*$//;t;s/^\s*\([^[:space:]]*\)\s*$/\1 -/p" exclude.txt >>exclude.tmp
- if not exist exclude.tmp goto add_include
-
- bin\sort -u packages.txt exclude.tmp -o packages.tmp
- bin\sed "/^.* -$/{:x;N;s/^\([^\n]*\) -\n\1-[[:digit:]].*$/\1 -/I;tx;D}" packages.tmp >packages.txt
- del packages.tmp
- del exclude.tmp
-
- ::
- :: Add packages in include.txt
- ::
- :add_include
- if not exist include.tmp goto shuffle
- copy include.tmp+packages.txt packages.tmp >nul
- del packages.txt
- del include.tmp
- ren packages.tmp packages.txt
-
- ::
- :: Shuffle package list and file list
- ::
- :shuffle
- bin\sed "s/^.*[^-]$/&-/" packages.txt >packages.tmp
- bin\sort filelist.txt packages.tmp -o filelist.tmp
- del packages.tmp
-
- ::
- :: Cancel all files which don't belong to a package
- ::
- bin\sed -n "h;N;s/^\([^\n]\+\)\n\1/\1/;tx;D;:x;G;P;D" filelist.tmp >filelist.txt
- del filelist.tmp
-
- ::
- :: Download the desired files from the server
- ::
- if not "%GNUWIN32_VERBOSE%"=="" echo = Starting download of all files found whithin the file list ...
- if not exist packages goto makepackages
- if not exist oldpacks goto makeoldpacks
-
- move /y packages\*.* oldpacks >nul
- rmdir /s /q packages
- goto makepackages
-
- :makeoldpacks
- ren packages oldpacks
-
- :makepackages
- mkdir packages
-
- :download
- echo %GNUWIN32_LOAD% >loadlist.tmp
- bin\sed "s/ *$//;s/ /\n/g" loadlist.tmp >loadlist.txt
- del loadlist.tmp
- cd packages
- for /f %%f in (..\filelist.txt) do (
- if not exist ..\oldpacks\%%f (
- for /f %%m in (..\loadlist.txt) do (
- if not exist %%f ..\bin\wget "%%m%%f"
- )
- ) else (
- move /y ..\oldpacks\%%f .
- )
- )
- cd ..
- del loadlist.txt
-
- ::
- :: Clean up things
- ::
- if not exist oldpacks goto bye
- dir /b oldpacks >oldpacks.txt
- bin\test -s oldpacks.txt
- if errorlevel 1 rmdir /s /q oldpacks
- if exist oldpacks.txt del oldpacks.txt
-
- :bye
- endlocal
-